﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using FTchina;

public partial class UI_Cache : BasePage
{

    protected void Page_Load(object sender, EventArgs e)
    {


        getaspnetn();
        GetCacheCount();
        GetAllCache();

    }
    /// <summary>
    /// 获取当前的ASP.NET进程占用内存
    /// </summary>
    /// <returns></returns>
    private void getaspnetn()
    {
        string temp;
        try
        {
            temp = ((Double)System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 / 1048576).ToString("N2");
        }
        catch
        {
            temp = "未知";
        }
        lblnc.Text = temp;
    }

    private void GetCacheCount()
    {
        lblcachecount.Text = HttpContext.Current.Cache.Count.ToString();
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        // FTchina.Caching.FTchinaCache.RemoveAllCache();
        GetCacheCount();
        GetAllCache();
        getaspnetn();
    }
    protected void GetAllCache()
    {
        System.Collections.IDictionaryEnumerator ss = HttpContext.Current.Cache.GetEnumerator();
        ArrayList al = new ArrayList();
        while (ss.MoveNext())
        {
            CacheMode cm = new CacheMode();
            cm.ckey = ss.Key.ToString();
            cm.cvalue = ss.Value.ToString();

            al.Add(cm);

        }
        Grid1.DataSource = al;
        Grid1.DataBind();
    }

    private class CacheMode
    {
        public string ckey { get; set; }
        public string cvalue { get; set; }

    }

    protected void Timer1_Tick(object sender, EventArgs e)
    {
        GetAllCache();
    }

    protected void btnUnload_Click(object sender, EventArgs e)
    {
        try
        {//终止当前应用程序，在下次接收到请求时重新启动

            HttpRuntime.UnloadAppDomain();
        }
        catch
        {//如果失败了就动webc.onfig的最后修改时间属性。
            string WebConfigPath = HttpContext.Current.Request.PhysicalApplicationPath + "\\Web.config";
            System.IO.File.SetLastWriteTimeUtc(WebConfigPath, DateTime.UtcNow);

        }
        GetAllCache();
    }

}
